<%@ page import="com.afishing.dao.ShopDao" %>
<%@ page import="com.afishing.dao.impl.ShopDaoImpl" %>
<%@ page import="com.afishing.entity.Shop" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.afishing.dao.CartDao" %>
<%@ page import="com.afishing.dao.impl.CartDapImpl" %><%--
  Created by IntelliJ IDEA.
  User: 王仕鹏
  Date: 2024/11/22
  Time: 10:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>购物车页面</title>
<%--    导入bootstrap-5.30-alpha1-dist--%>
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <script src="bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="css/shop.css">
</head>

<body>
<%
    ShopDao shopDao = new ShopDaoImpl();
    ArrayList<Shop> allShop = shopDao.getAllShop();
%>

<div class="shop_list">
    <table>
        <tr>
            <th>商品图片</th>
            <th>商品名称</th>
            <th>商品描述</th>
            <th>商品价格</th>
            <th>商品数量</th>
        </tr>
        <%
            ArrayList<Shop> checkList = new ArrayList<Shop>();
            for (Shop shop : allShop) {
        %>
        <tr>
            <td><img src="<%="imgs/"+shop.getImage()%>" width="200" height="150"  alt="商品图片"></td>
            <td><%=shop.getName()%></td>
            <td><%=shop.getDescription()%></td>
            <td><%=shop.getPrice()%></td>
            <td><%=shop.getAmount()%></td>
            <td><input type="checkbox" onclick="
                if(this.checked){
                    <%--将选中的商品id添加到checkList中--%>
                    console.log('<%=shop.getName()+"已被选中"%>');
                    <%checkList.add(shop);%>
                }

                                                "></td>
        </tr>
        <%
            }
        %>
        <%--        添加到购物车按钮--%>
        <tr>
            <td colspan="6">
                <input type="button" value="添加到购物车" onclick="updateCart()" >
            </td>
        </tr>
    </table>
</div>
<%--<div class="container text-center">--%>
<%--    <div class="row">--%>
<%--        <% for (Shop shop : allShop) { %>--%>
<%--        <div class="col">--%>
<%--            <span>商品编号：<%= shop.getId() %></span>--%>
<%--            <span>商品名称：<%= shop.getName() %></span>--%>
<%--            <span>商品价格：<%= shop.getPrice() %></span>--%>
<%--            <span>商品描述：<%= shop.getDescription() %></span>--%>
<%--            <span>商品数量：<%= shop.getAmount() %></span>--%>
<%--            <button class="btn btn-danger">加入购物车</button>--%>
<%--        </div>--%>
<%--        <% } %>--%>


<%--    </div>--%>
<%--</div>--%>
<%--<table border="1">--%>
<%--    <tr>--%>
<%--        <th>商品编号</th>--%>
<%--        <th>商品名称</th>--%>
<%--        <th>商品价格</th>--%>
<%--        <th>商品描述</th>--%>
<%--        <th>数量</th>--%>
<%--    </tr>--%>

<%--    <% for (Shop shop : allShop) { %>--%>
<%--    <tr>--%>
<%--        <td><%= shop.getId() %></td>--%>
<%--        <td><%= shop.getName() %></td>--%>
<%--        <td><%= shop.getPrice() %></td>--%>
<%--        <td><%= shop.getDescription() %></td>--%>
<%--        <td><%= shop.getAmount()%></td>--%>
<%--    </tr>--%>
<%--    <% } %>--%>
<%--</table>--%>

<span>====================================================</span>
<h1>展示购物车中的商品</h1>
<%
    CartDao cartDao = new CartDapImpl();
    ArrayList<Shop> allCartShops = cartDao.getAllShops();
%>

<div class="shop_list">
    <table>
        <tr>
            <th>商品图片</th>
            <th>商品名称</th>
            <th>商品描述</th>
            <th>商品价格</th>
            <th>商品数量</th>
        </tr>
        <%
            for (Shop shop : allCartShops) {
        %>
        <tr>
            <td><img src="<%="imgs/"+shop.getImage()%>" width="200" height="150"  alt="商品图片"></td>
            <td><%=shop.getName()%></td>
            <td><%=shop.getDescription()%></td>
            <td><%=shop.getPrice()%></td>
            <td><%=shop.getAmount()%></td>
            <td><input type="checkbox" onclick=""></td>
        </tr>
        <%
            }
        %>
        <%--        添加到购物车按钮--%>
    </table>
</div>

</body>
<script>
    window.onload = function () {
        console.log("页面加载完成");
        var checkList = [];
    }
    function addCart() {
        alert("添加到购物车");
    }
    function updateCart(list) {
        console.log(list);
        alert("添加到购物车");
    }
</script>
</html>
